﻿using Dapper;
using Estsh.Core.Base;
using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Extend.Models;
using Estsh.Core.Models;
using Estsh.Core.Services;
using Estsh.Core.Wms.IRepositories;
using Estsh.Core.Wms.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Estsh.Core.Wms.Services
{
    /// <summary>
    /// 零星出库
    /// </summary>
    public class ScatteredOutStockService : BaseService<BaseEntity>, IScatteredOutStockService
    {
        private readonly IScatteredOutStockRepository repository;
        public ScatteredOutStockService(IScatteredOutStockRepository _repository) : base(_repository)
        {
            repository = _repository;
        }
        public SetObjectDetail GetScatteredOutStockOrderList(string orderNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            List<WmsOutstock> wmsMoves = repository.GetScatteredOutStockOrderList(orderNo);
            if (wmsMoves.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "成功";
                rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }
        public SetObjectDetail GetScatteredOutStockOrderListByOrderNo(string orderNo)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();
            List<WmsOutstock_Extend> wmsMoves = repository.GetScatteredOutStockOrderListByOrderNo(orderNo);
            if (wmsMoves.Count > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "成功";
                rfInfo.wmsObjectDetail = wmsMoves.ConvertAll(s => (object)s);
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }

        public SetObjectDetail CheckStockByCartonAlocate(string cartonNo, string orderNo, string loginId)
        {
            List<SysStock> sysStockList = null;
            string strCartonNo = "";
            int refNum = 0;
            SetObjectDetail rfInfo = new SetObjectDetail();
            SysStock sysStocks = repository.GetStockByCartonNo(cartonNo);
            if (sysStocks.CartonType == 1)
            {
                //获取周转箱中的物料
                List<WmsRackPackage_Extend> rackPackageInfo = repository.GetCartonInfo(cartonNo);
                List<WmsOutstockDetail> outstockDetails = repository.GetOutstockOrderNo(orderNo);

                //判断周转箱内物料是否和单据物料一致
                for (int i = 0; i < rackPackageInfo.Count; i++)
                {
                    List<WmsOutstockDetail> outstockDetails1 = outstockDetails.Where(x => x.PartNo == rackPackageInfo[i].PartNo).ToList();
                    if (outstockDetails1.Count == 0)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "周转箱内物料与单据物料不一致！";
                        return rfInfo;
                    }
                    else
                    {
                        List<WmsOutstockDetail> outstockDetails2 = outstockDetails.Where(x => x.PartNo == rackPackageInfo[i].PartNo && x.Qty >= Convert.ToInt32(rackPackageInfo[i].RackNum)).ToList();
                        if (outstockDetails2.Count == 0)
                        {
                            rfInfo.type = "FAIL";
                            rfInfo.message = "[" + cartonNo + "]:周转箱下条码数量大于单据需求数量!";
                            return rfInfo;
                        }
                    }
                    strCartonNo += rackPackageInfo[i].CortonNo + "','"; 
                }
                if (strCartonNo.EndsWith("'"))
                    strCartonNo = strCartonNo.Substring(0,strCartonNo.Length-3);
                sysStockList = repository.GetStockByCartonNoList(strCartonNo);
            }
            else 
            {
                sysStockList = repository.GetStockByCartonNoList(cartonNo);
            }

            StringBuilder stringBuilder = new StringBuilder(1024);
            List<string> sqlStrings = new List<string>();
            List<DynamicParameters> parameterList = new List<DynamicParameters>();
            if (sysStockList.Count > 0)
            {
                for (int j = 0; j < sysStockList.Count; j++)
                {
                    if (sysStockList[j].Enabled != "Y")
                    {
                        //提示  [M0090105]:箱条码已冻结，无法操作!
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + sysStockList[j].CartonNo + "]:条码已冻结，无法操作!";
                        return rfInfo;
                    }
                    else if (sysStockList[j].Status != (int)WmsEnumUtil.StockStatus.INSTOCKED)
                    {
                        //提示  [M0090105]:该条码是**状态，无法操作!
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + sysStockList[j].CartonNo + "]:该条码不是已上架状态，请检查!";
                        return rfInfo;
                    }

                    List<WmsOutstock> WmsOutstocks = repository.GetOutStockByOrderNo(orderNo);
                    if (WmsOutstocks.Count == 0)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + orderNo + "]:该单据是未创建或已关闭状态，请检查!";
                        return rfInfo;
                    }

                    List<WmsOutstockDetail> outstockDetailsErp = repository.GetOutstockByOrderNoSrcErp(orderNo, sysStockList[j].ErpWarehouse);
                    if (outstockDetailsErp.Count == 0)
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + sysStockList[j].CartonNo + "]:该条码对应库存地不在单据内!";
                        return rfInfo;
                    }

                    List<WmsOutstockDetail> WmsOutstockDetails = repository.GetOutstockByOrderNoPartNo(orderNo, sysStockList[j].PartNo);
                    if (WmsOutstockDetails.Count == 0)
                    {
                        //提示  [M0090105]:该条码零件号不在单据内!
                        rfInfo.type = "FAIL";
                        rfInfo.message = "[" + sysStockList[j].CartonNo + "]:该条码零件号不在单据内!";
                        return rfInfo;
                    }                    
                    
                    
                    for (int i = 0; i < WmsOutstockDetails.Count; i++)
                    {
                        int remainNum = Convert.ToInt32(WmsOutstockDetails[i].Qty - WmsOutstockDetails[i].OutQty);//余数
                        if (sysStockList[j].Qty == remainNum || sysStockList[j].Qty < remainNum)
                        {
                            if (WmsOutstocks[0].OrderStatus != (int)WmsEnumUtil.MoveOrderDetailStatus.BATCHING)//
                            { //已完成
                                stringBuilder = new StringBuilder(1024);
                                stringBuilder.Append("UPDATE wms_outstock SET order_status=" + (int)WmsEnumUtil.MoveOrderDetailStatus.BATCHING + ",update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no='" + orderNo + "';");
                                sqlStrings.Add(stringBuilder.ToString());
                            }
                            stringBuilder = new StringBuilder(1024);
                            stringBuilder.Append("UPDATE wms_outstock_detail SET out_qty+=" + sysStockList[j].Qty + ",item_status=" + (int)WmsEnumUtil.MoveOrderDetailStatus.COMPLETED + " ,update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  ruid='" + WmsOutstockDetails[i].Ruid + "';");
                            sqlStrings.Add(stringBuilder.ToString());

                            stringBuilder = new StringBuilder(1024);
                            stringBuilder.Append("UPDATE sys_stock SET status=" + (int)WmsEnumUtil.StockStatus.OUTSTOCKED + ",locate_id=0,locate_name='',zone_id=0,zone_name='',warehouse_id=0,warehouse_name='',update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  carton_no='" + sysStockList[j].CartonNo + "';");
                            sqlStrings.Add(stringBuilder.ToString());

                            stringBuilder = new StringBuilder(1024);
                            stringBuilder.Append("INSERT INTO dbo.wms_outstock_sn ");
                            stringBuilder.Append("( ");
                            stringBuilder.Append("    order_no, ");
                            stringBuilder.Append("    item_no, ");
                            stringBuilder.Append("    part_id, ");
                            stringBuilder.Append("    part_no, ");
                            stringBuilder.Append("    part_spec, ");
                            stringBuilder.Append("    carton_no, ");
                            stringBuilder.Append("    qty, ");
                            stringBuilder.Append("    unit, ");
                            stringBuilder.Append("    status, ");
                            stringBuilder.Append("    factory_id, ");
                            stringBuilder.Append("    factory_code, ");
                            stringBuilder.Append("    enabled, ");
                            stringBuilder.Append("    create_userid, ");
                            stringBuilder.Append("    create_time, ");
                            stringBuilder.Append("    guid ");
                            stringBuilder.Append(") ");
                            stringBuilder.Append("VALUES ");
                            stringBuilder.Append("(   N'" + orderNo + "', ");
                            stringBuilder.Append("    '" + WmsOutstockDetails[i].ItemNo + "',");
                            stringBuilder.Append("    " + WmsOutstockDetails[i].PartId + ", ");
                            stringBuilder.Append("    N'" + WmsOutstockDetails[i].PartNo + "',");
                            stringBuilder.Append("    N'" + WmsOutstockDetails[i].PartSpec + "',");
                            stringBuilder.Append("    '" + sysStockList[j].CartonNo + "',");
                            stringBuilder.Append("    " + sysStockList[j].Qty + ", ");
                            stringBuilder.Append("    '" + sysStockList[j].Unit + "',");
                            stringBuilder.Append("    " + (int)WmsEnumUtil.MoveOrderSnStatus.PROCESSED + ",");//处理中
                            stringBuilder.Append("    " + sysStockList[j].FactoryId + ", ");
                            stringBuilder.Append("    N'" + sysStockList[j].FactoryCode + "', ");
                            stringBuilder.Append("    'Y', ");
                            stringBuilder.Append("   " + loginId + " ,  ");
                            stringBuilder.Append("    CONVERT(VARCHAR(20),GETDATE(),21), ");
                            stringBuilder.Append("    newid()");
                            stringBuilder.Append("    );");
                            sqlStrings.Add(stringBuilder.ToString());
                            break;
                        }
                        else if (sysStockList[j].Qty > remainNum)
                        {
                            if (WmsOutstockDetails.Count - 1 == i)
                            {
                                rfInfo.type = "FAIL";
                                rfInfo.message = "[" + sysStockList[j].CartonNo + "]:该条码库存大于单据需求数量!";
                                return rfInfo;
                            }
                        }
                    }

                    stringBuilder = new StringBuilder(1024);
                    stringBuilder.Append("INSERT INTO dbo.sys_stock_trans ");
                    stringBuilder.Append("( ");
                    stringBuilder.Append("    trans_code, ");
                    stringBuilder.Append("    carton_no, ");
                    stringBuilder.Append("    part_id, ");
                    stringBuilder.Append("    part_no, ");
                    stringBuilder.Append("    part_spec, ");
                    stringBuilder.Append("    src_locate_id, ");
                    stringBuilder.Append("    src_locate_name, ");
                    stringBuilder.Append("    dest_locate_id, ");
                    stringBuilder.Append("    dest_locate_name, ");
                    stringBuilder.Append("    old_qty, ");
                    stringBuilder.Append("    new_qty, ");
                    stringBuilder.Append("    trans_qty, ");
                    stringBuilder.Append("    old_status, ");
                    stringBuilder.Append("    new_status, ");
                    stringBuilder.Append("    unit, ");
                    stringBuilder.Append("    factory_id, ");
                    stringBuilder.Append("    factory_code, ");
                    stringBuilder.Append("    src_erp_warehouse, ");
                    stringBuilder.Append("    dest_erp_warehouse, ");
                    stringBuilder.Append("    src_warehouse_id, ");
                    stringBuilder.Append("    src_warehouse_name, ");
                    stringBuilder.Append("    dest_warehouse_id, ");
                    stringBuilder.Append("    dest_warehouse_name, ");
                    stringBuilder.Append("    src_zone_id, ");
                    stringBuilder.Append("    src_zone_name, ");
                    stringBuilder.Append("    dest_zone_id, ");
                    stringBuilder.Append("    dest_zone_name, ");
                    stringBuilder.Append("    enabled, ");
                    stringBuilder.Append("    create_userid, ");
                    stringBuilder.Append("    create_time, ");
                    stringBuilder.Append("    update_userid, ");
                    stringBuilder.Append("    update_time, ");
                    stringBuilder.Append("    guid ");
                    stringBuilder.Append(") ");
                    stringBuilder.Append("VALUES ");
                    stringBuilder.Append(" ('" + (int)WmsEnumUtil.TransType.SCATTERED_OUTSTOCK + "', ");//零星出库
                    stringBuilder.Append("    '" + sysStockList[j].CartonNo + "', ");
                    stringBuilder.Append("    " + sysStockList[j].PartId + ", ");
                    stringBuilder.Append("    '" + sysStockList[j].PartNo + "',  ");
                    stringBuilder.Append("    '" + sysStockList[j].PartSpec + "', ");
                    stringBuilder.Append("    " + sysStockList[j].LocateId + ",  ");//源库位
                    stringBuilder.Append("    '" + sysStockList[j].LocateName + "',  ");
                    stringBuilder.Append("    0, ");//目标库位
                    stringBuilder.Append("    '',  ");
                    stringBuilder.Append("    " + sysStockList[j].Qty + ",");
                    stringBuilder.Append("    " + sysStockList[j].Qty + ",");
                    stringBuilder.Append("    " + sysStockList[j].Qty + ",");
                    stringBuilder.Append("    '" + sysStockList[j].Status + "', ");
                    stringBuilder.Append("    '" + (int)WmsEnumUtil.StockStatus.OUTSTOCKED + "', ");
                    stringBuilder.Append("    '" + sysStockList[j].Unit + "', ");
                    stringBuilder.Append("    " + sysStockList[j].FactoryId + ", ");
                    stringBuilder.Append("    '" + sysStockList[j].FactoryCode + "',");
                    stringBuilder.Append("    '" + sysStockList[j].ErpWarehouse + "',");
                    stringBuilder.Append("    '', ");//目标ERP库存地
                    stringBuilder.Append("    " + sysStockList[j].WarehouseId + ", ");
                    stringBuilder.Append("    '" + sysStockList[j].WarehouseName + "', ");
                    stringBuilder.Append("    0, ");
                    stringBuilder.Append("    '', ");//目标仓库
                    stringBuilder.Append("    " + sysStockList[j].ZoneId + ",  ");
                    stringBuilder.Append("    '" + sysStockList[j].ZoneName + "',  ");
                    stringBuilder.Append("    0, ");//目标库区
                    stringBuilder.Append("    '',  ");
                    stringBuilder.Append("    'Y', ");
                    stringBuilder.Append("    " + loginId + ", ");
                    stringBuilder.Append("    CONVERT(VARCHAR(20),GETDATE(),21), ");
                    stringBuilder.Append("    " + loginId + ", ");
                    stringBuilder.Append("    CONVERT(VARCHAR(20),GETDATE(),21), ");
                    stringBuilder.Append("    NEWID()  ");
                    stringBuilder.Append("    ) ; ");
                    sqlStrings.Add(stringBuilder.ToString());

                    
                }
                refNum = repository.SQLTransaction(sqlStrings, parameterList);
            }
            else 
            {
                //提示  [M0090105]:该条码不可用，请检查!
                rfInfo.type = "FAIL";
                rfInfo.message = "[" + cartonNo + "]:该条码不存在，请检查!";
                return rfInfo;
            }


            if (refNum > 0)
            {
                List<WmsOutstock> wmsMoves = repository.GetOutstockByOrderNo(orderNo);
                if (wmsMoves.Count > 0)
                {
                    List<WmsOutstockDetail> wmsMoves1 = repository.GetOutstockDetailByOrderNo(orderNo);
                    for (int i = 0; i < wmsMoves1.Count; i++)
                    {
                        if (wmsMoves1[i].Qty != wmsMoves1[i].OutQty)
                        {
                            rfInfo.type = "PASS";
                            rfInfo.message = "操作成功!请继续扫描箱条码或周转箱";
                            rfInfo.wmsObjectDetail = wmsMoves1.ConvertAll(s => (object)s);
                            return rfInfo;
                        }
                    }

                    int updateStatus = 1;
                    sqlStrings = new List<string>();
                    parameterList = new List<DynamicParameters>();
                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    DynamicParameters parameters = new DynamicParameters();

                    List<WmsOutstockDetail> wmsOutstockDetails = repository.GetFinishOutStockDetailByOrderNo(orderNo);
                    if (wmsOutstockDetails.Count > 0)
                    {
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_MOVR(ZINSTNO,ZEILE,WERKS,LGORT,UMLGO,MATNR,ERFMG ");
                        SqlStringBuilder.Append("           ,ERFME,ACTION,ZPOST,ZTIME,SID,RECTIM,SYNFLG ");
                        SqlStringBuilder.Append("           ,GUID) ");
                        SqlStringBuilder.Append("     VALUES(@ZINSTNO,@ZEILE,@WERKS,@LGORT,@UMLGO,@MATNR,@ERFMG,@ERFME ");
                        SqlStringBuilder.Append("           ,@ACTION,@ZPOST,@ZTIME,@SID,@RECTIM,@SYNFLG ");
                        SqlStringBuilder.Append("           ,@GUID) ");

                        for (int i = 0; i < wmsOutstockDetails.Count; i++)
                        {
                            SysPart sysPart = repository.GetPartNOInfoByPartNo(wmsOutstockDetails[i].PartNo);
                            sqlStrings.Add(SqlStringBuilder.ToString());
                            parameters = new DynamicParameters();
                            parameters.Add("@ZINSTNO", wmsOutstockDetails[i].OrderNo);//盘点凭证号
                            parameters.Add("@ZEILE", (i + 1) * 10);//行号
                            parameters.Add("@WERKS", wmsOutstockDetails[i].FactoryCode);//工厂
                            parameters.Add("@LGORT", wmsOutstockDetails[i].SrcErpWarehouse);//发出库存地点
                            parameters.Add("@UMLGO", "");//接收库存地点
                            parameters.Add("@MATNR", wmsOutstockDetails[i].PartNo);//物料编码
                            parameters.Add("@ERFMG", wmsOutstockDetails[i].OutQty);//转储数量
                            if (sysPart == null)
                            {
                                parameters.Add("@ERFME", "");//计量单位
                            }
                            else
                            {
                                parameters.Add("@ERFME", sysPart.Unit);//计量单位
                            }
                            parameters.Add("@ACTION", "M06"); //M06:零星出库
                            parameters.Add("@ZPOST", DateTime.Now.ToString("yyyyMMdd"));//交易日期
                            parameters.Add("@ZTIME", DateTime.Now.ToString("HHmmss"));//交易时间
                            parameters.Add("@SID", Guid.NewGuid().ToString().Replace("-", ""));
                            parameters.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                            parameters.Add("@SYNFLG", "N");
                            parameters.Add("@GUID", Guid.NewGuid().ToString());
                            parameterList.Add(parameters);
                        }
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("UPDATE wms_outstock SET order_status=" + (int)WmsEnumUtil.MoveOrderStatus.COMPLETED + ",update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                        sqlStrings.Add(SqlStringBuilder.ToString());
                        parameters = new DynamicParameters();
                        parameters.Add("@orderNo", orderNo);
                        parameterList.Add(parameters);
                        
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("UPDATE wms_outstock_detail SET item_status=" + (int)WmsEnumUtil.MoveOrderDetailStatus.COMPLETED + ",update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                        sqlStrings.Add(SqlStringBuilder.ToString());
                        parameters = new DynamicParameters();
                        parameters.Add("@orderNo", orderNo);
                        parameterList.Add(parameters);

                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("UPDATE wms_outstock_sn SET status=" + (int)WmsEnumUtil.MoveOrderSnStatus.PROCESSED + ",update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                        sqlStrings.Add(SqlStringBuilder.ToString());
                        parameters = new DynamicParameters();
                        parameters.Add("@orderNo", orderNo);
                        parameterList.Add(parameters);

                        updateStatus = repository.SQLTransaction(sqlStrings, parameterList);
                    }
                    if (updateStatus > 0)
                    {
                        rfInfo.type = "PASS";
                        rfInfo.message = "单据操作完成!";
                    }
                    else
                    {
                        rfInfo.type = "FAIL";
                        rfInfo.message = "单据操作操作失败!请检查";
                    }
                }
                else
                {
                    rfInfo.type = "FAIL";
                    rfInfo.message = "未查询到数据，请检查！";
                }
            }
            else
            {
                //提示  操作失败!
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }
        public SetObjectDetail SetScatteredOutStockOrderNoSubmit(string orderNo, string loginId)
        {
            SetObjectDetail rfInfo = new SetObjectDetail();//返回消息
            List<string> sqlStrings = new List<string>();
            List<DynamicParameters> parameterList = new List<DynamicParameters>();
            StringBuilder SqlStringBuilder = new StringBuilder(1024);
            DynamicParameters parameters = new DynamicParameters();
            int updateStatus = 1;
            List<WmsOutstockDetail> wmsOutstockDetails = repository.GetFinishOutStockDetailByOrderNo(orderNo);
            if (wmsOutstockDetails.Count > 0)
            {
                SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("INSERT INTO dbo.WMS_MOVR(ZINSTNO,ZEILE,WERKS,LGORT,UMLGO,MATNR,ERFMG ");
                SqlStringBuilder.Append("           ,ERFME,ACTION,ZPOST,ZTIME,SID,RECTIM,SYNFLG ");
                SqlStringBuilder.Append("           ,GUID) ");
                SqlStringBuilder.Append("     VALUES(@ZINSTNO,@ZEILE,@WERKS,@LGORT,@UMLGO,@MATNR,@ERFMG,@ERFME ");
                SqlStringBuilder.Append("           ,@ACTION,@ZPOST,@ZTIME,@SID,@RECTIM,@SYNFLG ");
                SqlStringBuilder.Append("           ,@GUID) ");

                for (int i = 0; i < wmsOutstockDetails.Count; i++)
                {
                    SysPart sysPart = repository.GetPartNOInfoByPartNo(wmsOutstockDetails[i].PartNo);
                    sqlStrings.Add(SqlStringBuilder.ToString());
                    parameters = new DynamicParameters();
                    parameters.Add("@ZINSTNO", wmsOutstockDetails[i].OrderNo);//盘点凭证号
                    parameters.Add("@ZEILE", (i + 1) * 10);//行号
                    parameters.Add("@WERKS", wmsOutstockDetails[i].FactoryCode);//工厂
                    parameters.Add("@LGORT", wmsOutstockDetails[i].SrcErpWarehouse);//发出库存地点
                    parameters.Add("@UMLGO", "");//接收库存地点
                    parameters.Add("@MATNR", wmsOutstockDetails[i].PartNo);//物料编码
                    parameters.Add("@ERFMG", wmsOutstockDetails[i].OutQty);//转储数量
                    if (sysPart == null)
                    {
                        parameters.Add("@ERFME", "");//计量单位
                    }
                    else
                    {
                        parameters.Add("@ERFME", sysPart.Unit);//计量单位
                    }
                    parameters.Add("@ACTION", "M06"); //M06:零星出库
                    parameters.Add("@ZPOST", DateTime.Now.ToString("yyyyMMdd"));//交易日期
                    parameters.Add("@ZTIME", DateTime.Now.ToString("HHmmss"));//交易时间
                    parameters.Add("@SID", Guid.NewGuid().ToString().Replace("-", ""));
                    parameters.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    parameters.Add("@SYNFLG", "N");
                    parameters.Add("@GUID", Guid.NewGuid().ToString());
                    parameterList.Add(parameters);
                }

                SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("UPDATE wms_outstock SET order_status='40',update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                sqlStrings.Add(SqlStringBuilder.ToString());
                parameters = new DynamicParameters();
                parameters.Add("@orderNo", orderNo);
                parameterList.Add(parameters);

                SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("UPDATE wms_outstock_detail SET item_status='40',update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                sqlStrings.Add(SqlStringBuilder.ToString());
                parameters = new DynamicParameters();
                parameters.Add("@orderNo", orderNo);
                parameterList.Add(parameters);

                SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("UPDATE wms_outstock_sn SET status=" + (int)WmsEnumUtil.MoveOrderSnStatus.PROCESSED + ",update_userid=" + loginId + ",update_time=CONVERT(VARCHAR(20),GETDATE(),21) WHERE  order_no=@orderNo;");
                sqlStrings.Add(SqlStringBuilder.ToString());
                parameters = new DynamicParameters();
                parameters.Add("@orderNo", orderNo);
                parameterList.Add(parameters);

                updateStatus = repository.SQLTransaction(sqlStrings, parameterList);
            }

            if (updateStatus > 0)
            {
                rfInfo.type = "PASS";
                rfInfo.message = "[" + orderNo + "]单据已提交，请重新选择单据";
            }
            else
            {
                rfInfo.type = "FAIL";
                rfInfo.message = "未查询到数据，请检查！";
            }
            return rfInfo;
        }
    }
}
